<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;

/**
 * 老师逻辑
 */
class Teacher extends AdminBase
{
    

    
    /**
     * 获取老师列表
     */
    public function getArticleList($where = [], $field = 'a.*,m.nickname', $order = '')
    {
        
        $this->modelCourseTeacher->alias('a');
        


        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        return $this->modelCourseTeacher->getList($where, $field, $order);
    }
    
    /**
     * 获取老师列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.name'] = ['like', '%'.$data['search_data'].'%'];
        
        return $where;
    }
    
    /**
     * 老师信息编辑
     */
    public function articleEdit($data = [])
    {

        $validate_result = $this->validateTeacher->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateTeacher->getError()];
        }
        
        $url = url('articleList');
        
        empty($data['id']) && $data['member_id'] = MEMBER_ID;
        
//      $data['content'] = htmlspecialchars_decode($data['content']);

        $result = $this->modelCourseTeacher->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '老师' . $handle_text . '，name：' . $data['name']);
        
        return $result ? [RESULT_SUCCESS, '老师操作成功', $url] : [RESULT_ERROR, $this->modelCourseTeacher->getError()];
    }

    /**
     * 获取老师信息
     */
    public function getArticleInfo($where = [], $field = 'a.*,m.nickname')
    {
        
        $this->modelCourseTeacher->alias('a');
        

        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        

        
        return $this->modelCourseTeacher->getInfo($where, $field);
    }
    

    
    /**
     * 老师删除
     */
    public function articleDel($where = [])
    {
        
        $result = $this->modelCourseTeacher->deleteInfo($where);
        
        $result && action_log('删除', '老师删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '老师删除成功'] : [RESULT_ERROR, $this->modelCourseTeacher->getError()];
    }

    /**
     * 老师删除
     */
    public function update_info($where = [])
    {

        //dd($where);

        $result = $this->modelCourseTeacher->setInfo($where);


        return $result ? [RESULT_SUCCESS, '操作成功'] : [RESULT_ERROR, '操作失败'];
    }
}
